unit Cons_IcmsDiferido;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, Grids, DBGrids, StdCtrls, Buttons, ExtCtrls,
  TFlatButtonUnit;

type
  TFrmCons_IcmsDiferido = class(TFrmConsulta)
    Label2: TLabel;
    ed_descricao: TEdit;
    dbg: TDBGrid;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure ed_descricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BtnFecharClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmCons_IcmsDiferido: TFrmCons_IcmsDiferido;
  xcons_icmsdif: string;

implementation

uses dm, db, dbtables, clsIcmsDiferido;

var
  icmsdiferido: TIcmsDiferido;
  tq: TQuery;
  tds: TDataSource;

{$R *.DFM}

procedure TFrmCons_IcmsDiferido.FormCreate(Sender: TObject);
begin
  inherited;
  icmsdiferido := TIcmsDiferido.Create;
  tq := TQuery.Create(self);
  tds := TDataSource.Create(self);
  tq.databasename := dmint.db.databasename;
  tq.active := false;
  tds.dataset := tq;
  dbg.datasource := tds;
end;

procedure TFrmCons_IcmsDiferido.FormDestroy(Sender: TObject);
begin
  inherited;
  icmsdiferido.free;
  tq.free;
  tds.free;
end;

procedure TFrmCons_IcmsDiferido.FormActivate(Sender: TObject);
begin
  inherited;
  icmsdiferido.Consultar(' ', tq);
end;

procedure TFrmCons_IcmsDiferido.ed_descricaoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    if ed_descricao.text = '' then ed_descricao.text := ' ';
    icmsdiferido.Consultar(ed_descricao.text, tq);
  end;
end;

procedure TFrmCons_IcmsDiferido.BtnFecharClick(Sender: TObject);
begin
  inherited;
  xcons_icmsdif := tq.fieldbyname('Icms_Codigo').asstring;
end;

end.
